package com.huiquan.vocab.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabElementOOaEqualsDisplay;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class VocabElementOOaEqualsDisplayDao extends EnhancedBaseDao<VocabElementOOaEqualsDisplay> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "VOCAB_ELEMENT_O_OA_EQUALS_DISPLAY.";

	public VocabElementOOaEqualsDisplayDao() {
		super(space);
	}

	public void batchInsert(List<VocabElementOOaEqualsDisplay> list) {
		int start = 0, end, size = list.size();
		List<VocabElementOOaEqualsDisplay> tempList;

		while (start < size) {
			if (start + 1000 < size) {
				end = start + 1000;
			} else {
				end = size;
			}
			tempList = list.subList(start, end);
			this.insert(space + "BATCH_INSERT", tempList, sqlMapClient);
			start += 1000;
		}
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveWrongEquals() {
		return (List<String>) this.list(space + "RETRIEVE_WRONG_EQUALS", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveWrongFlags() {
		return (List<String>) this.list(space + "RETRIEVE_WRONG_FLAGS", sqlMapClient);
	}

	public void setFlagByIds(String ids, Integer flag) {
		
		Map<String, Object> param = new HashMap<>();
		param.put("ids", ids);
		param.put("flag", flag);
		
		this.update(space + "SET_FLAG_BY_IDS", param, sqlMapClient);
	}

	public void reset() {
		this.update(space + "RESET", sqlMapClient);
	}
}
